<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>账号</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/style/admin.css" rel="stylesheet" />
    <link href="/node_modules/LobsterUIFrame/layuiadmin/layui/css/modules/layui-icon-extend/iconfont.css"
        rel="stylesheet" />
    <script src="/node_modules/LobsterUIFrame/layuiadmin/layui/layui.js"></script>
</head>


<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-input-inline">
                    <div class="layui-input-inline" style="width: 200px;">
                        <input type="text" name="accountNo" placeholder="请输入账号，姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">用户类型：</label>
                    <div class="layui-input-inline">
                        <select name="usertype">
                            <option value="-1">全部</option>
                            <option value="1">患者用户</option>
                            <option value="2">后台用户</option>
                        </select>
                    </div>
                </div>
                <div class="layui-input-inline">
                    <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="LAY-app-front-search"
                        id="btnSearch">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查找
                    </button>
                </div>
            </div>

            <div class="layui-card-body">
                <table id="datatable" lay-filter="datatable"></table>
            </div>
        </div>
    </div>
</body>

<script type="text/html" id="operation">
    {{# if(d.FrozenStatus==0) { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="frozen"><i class="layui-icon layui-icon-edit"></i>冻结</a>
    {{# }else { }}
    <a class="layui-btn layui-btn-xs" lay-event="unfreeze"><i class="layui-icon layui-icon-edit"></i>解冻</a>
    {{# } }}
</script>

</html>

<script>
    layui.config({
        base: '/node_modules/LobsterUIFrame/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    });

    layui.define(['index', 'layer', 'form', 'element', 'table', 'laydate'], function () {
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        var table = layui.table;
        var $ = layui.$;
        var admin = layui.admin;
        var setter = layui.setter;
        var laydate = layui.laydate;

        var controller = {
            data: {
                table: null,
                tableoptions: {},
                layerindex: 0,
                selectdata: {},
            },
            //初始化页面
            initpage: function () {
                this.initevent();
                this.loaddata();
            },
            getbaseurl: function (fun) {
                var url = "/lowcode/APP20210728142518705/wallet/?view=layui&fun=" + fun;
                return url;
            },
            //初始化事件
            initevent: function () {
                var self = this;
                //查找reload,通过条件，查询网格的table重载数据显示到界面
                form.on("submit(LAY-app-front-search)", function (data) {
                    self.loaddata();
                });
                //监听行工具事件
                table.on('tool(datatable)', function (obj) {  //tool是工具条事件名，UserInfoTable是table原始容器的属性
                    var data = obj.data;//当前行数据
                    var tr = obj.tr;
                    var layEvent = obj.event;//获得lay-event的值
                    //冻结
                    if (layEvent === "frozen") {
                        self.openForzen('确定冻结账户吗?冻结后影响账户提现，充值等', data.AccountId, 1)
                    } else if (layEvent == 'unfreeze') {
                        self.openForzen('确定解结账户吗?', data.AccountId, 0)
                    }
                })
            },
            //加载订单列表
            loaddata: function () {
                var self = this;
                var date = $("#date").val() || "";
                self.data.table = table.render({
                    elem: '#datatable',
                    where: {
                        accountNo: $("[name='accountNo']").val(),
                        usertype: $("[name='usertype']").val()
                    },
                    url: self.getbaseurl("Wallet.getaccountlist"),
                    height: 'full-130',
                    cellMinWidth: 80,
                    size: 'sm',
                    page: true,
                    cols: [[
                        { width: "12%", field: 'AccountNo', title: '账号' },
                        { width: "8%", field: 'Name', title: '姓名' },
                        { width: "12%", field: 'IDCard', title: '身份证' },
                        {
                            width: "8%", field: 'FrozenStatus', title: '冻结状态', templet: function (d) {
                                if (d.FrozenStatus == 0) {
                                    return '未冻结'
                                } else {
                                    return "<span style='color:red;'>已冻结</span>"
                                }
                            }
                        },
                        {
                            width: "8%", field: 'Balance', title: '余额', templet: function (d) {
                                return parseFloat((d.Balance || 0)).toFixed(2);
                            }
                        },
                        {
                            width: "8%", field: 'FrozenBalance', title: '冻结余额', templet: function (d) {
                                return parseFloat((d.FrozenBalance || 0)).toFixed(2);
                            }
                        },
                        { width: "8%", field: 'UserId', title: '用户ID' },
                        {
                            width: "8%", field: 'UserType', title: '用户类型', templet: function (d) {
                                if (d.UserType == 1) {
                                    return '患者用户';
                                } else if (d.UserType == 2) {
                                    return '后台用户';
                                }
                            }
                        },
                        { title: '操作', align: 'left', toolbar: '#operation', width: "28%", fixed: 'right' }   //操作script的id 
                    ]]
                })
            },
            openForzen(title, accountId, status) {
                var self = this;
                layer.confirm(title, { icon: status == 1 ? 2 : 1, title: "提示" },
                    function (index) {
                        var load = layer.msg('正在处理，请稍候', { icon: 16, time: 0, shade: [0.3, '#393D49'] });
                        admin.req({
                            type: "get",
                            url: self.getbaseurl("Wallet.frozen"),
                            data: {
                                accountId: accountId,
                                status: status,
                            },
                            done: function (res) {
                                layer.msg(res.msg);
                                self.data.table.reload();// 数据刷新
                                layer.close(index); //关闭弹层
                            },
                            complete: function () {
                                layer.close(load);
                            }
                        });
                    }
                )
            }
        }
        /*
        * 入口
        */
        controller.initpage();
    });

</script>